﻿namespace FrameWork.Lib.HTML
{
    using System;
    using System.Collections;
    using System.Reflection;

    public class HtmlAttributeCollection : CollectionBase
    {
        private HtmlElement mElement;

        public HtmlAttributeCollection()
        {
            this.mElement = null;
        }

        internal HtmlAttributeCollection(HtmlElement element)
        {
            this.mElement = element;
        }

        public int Add(HtmlAttribute attribute)
        {
            return base.List.Add(attribute);
        }

        public HtmlAttribute FindByName(string name)
        {
            if (this.IndexOf(name) == -1)
            {
                return null;
            }
            return this[this.IndexOf(name)];
        }

        public int IndexOf(string name)
        {
            for (int i = 0; i < base.List.Count; i++)
            {
                if (this[i].Name.ToLower().Equals(name.ToLower()))
                {
                    return i;
                }
            }
            return -1;
        }

        public HtmlAttribute this[string name]
        {
            get
            {
                return this.FindByName(name);
            }
        }

        public HtmlAttribute this[int index]
        {
            get
            {
                return (HtmlAttribute) base.List[index];
            }
            set
            {
                base.List[index] = value;
            }
        }
    }
}

